package com.ncmmall.application.business.cancelcarse;

import com.ncmmall.domain.business.setting.CancelCause;
import com.ncmmall.domain.business.setting.CancelCauseRepository;
import com.ncmmall.querychannel.service.QueryChannelService;
import com.google.common.collect.ImmutableMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;

/**
 * @author linxs
 * @Description: 取消原因业务类
 * @Date: 2019-11-12 16:30
 */
@Service
@Transactional
public class CancelCauseApplication {

    @Autowired
    private CancelCauseRepository cancelCauseRepository;

    @Autowired
    private QueryChannelService queryChannelService;

    /**
     * 添加
     *
     * @param cancelCause
     */
    public void create(CancelCause cancelCause) {
        cancelCause.setCreateTime(new Timestamp(System.currentTimeMillis()));
        cancelCause.setStatus(1);
        cancelCauseRepository.save(cancelCause);
    }

    /**
     * 修改
     *
     * @param params
     */
    public void modify(CancelCause params) {

        CancelCause cancelCause = queryChannelService.findOne("select c from CancelCause c where c.id = :id ", ImmutableMap.of("id", params.getId()), CancelCause.class);
        cancelCause.setCouse(params.getCouse());
        cancelCause.setSorz(params.getSorz());
        cancelCauseRepository.save(cancelCause);

    }

    /**
     * 删除
     *
     * @param params
     */
    public void remove(CancelCause params) {

        cancelCauseRepository.delete(params);

    }

    public void enabled(CancelCause params) {
        params.setStatus(1);
        cancelCauseRepository.save(params);
    }

    public void disable(CancelCause params) {
        params.setStatus(2);
        cancelCauseRepository.save(params);
    }
}
